import Vue from 'vue'
import VueRouter from 'vue-router'
const Login = () => import('components/common/login/Login')
const ElementHome = () => import('components/common/element/ElementHome')
const Welcome = () => import('views/welcome/Welcome')
const Users = () => import('views/users/Users')
const Rights = () => import('views/power/rights/Rights')
const Roles = () => import('views/power/roles/Roles')
const Categories = ()=>import('views/goods/Categories')
const Params = ()=>import('views/goods/Params') 
const Goods = ()=>import('views/goods/Goods')
const AddGoods = ()=>import('views/goods/AddGoods')
const Reports =()=> import ('views/reports/Reports')
const StoreList =()=>import('views/store/StoreList')
const AddStore =()=>import('views/store/AddStore')
const EditStore =()=>import('views/store/EditStore')
const MemberList =()=>import('views/member/MemberList')
const LabelManage =()=>import('views/member/LabelManage')

Vue.use(VueRouter)

  const routes = [
  {
    path: '/',
    name: '',
    redirect:'/login',
  },
  {
    path: '/login',
    name: 'Login',
    component:Login
  },
  {
    path: '/elementHome',
    name: 'ElementHome',
    component:ElementHome,
    redirect:'welcome',
    children:[
      {
        path:'/storelist',
        name:'StoreList',
        component:StoreList
      },
      {
        path:'/addstore',
        name:'AddStore',
        component:AddStore
      },
      {
        path:'/editstore',
        name:'EditStore',
        component:EditStore
      },
      {
        path:'/memberlist',
        name:'MemberList',
        component:MemberList
      },
      {
        path:'/labelmanage',
        name:'LabelManage',
        component:LabelManage
      },
      {
      path:'/welcome',
      name:'Welcome',
      component:Welcome
      },{
      path:'/users',
      name:'Users',
      component:Users
      },{
        path:'/rights',
        name:'Rights',
        component:Rights
      },
      {
        path:'/roles',
        name:'Roles',
        component:Roles
      },
      {
        path:'/categories',
        name:'Categories',
        component:Categories
      },
      {
        path:'/params',
        name:'Params',
        component:Params
      },
      {
        path:'/goods',
        name:'Goods',
        component:Goods,  
      },
      {
        path:'/goods/AddGoods',
        name:'AddGoods',
        component:AddGoods
      },
      {
        path:'/reports',
        name:'Reports',
        component:Reports
      }
    ]
  }
]

const router = new VueRouter({
  routes,
  mode:'history'
})

// 挂载路由导航守卫
router.beforeEach((to,form,next)=>{
  if(to.path=='/login'){
    return next();
  }
  //获取token
  const tokenStr=window.sessionStorage.getItem('token');
  if(!tokenStr){
     return next('/login')
  }else{
    next();
  }
})
export default router
